// store.js
import { defineStore } from 'pinia';

export const useweatherStore = defineStore('weatherResult', {
  state: () => ({
    results: [], // Array to store results and timestamps
  }),
  actions: {
    setResult(weatherResult) {
      const timestamp = new Date(); // Get the current timestamp
      this.results.push({ weatherResult, timestamp }); // Push the result and timestamp to the array
    },
  },
  getters: {
    getResultsByHour: (state) => (hour) => {
      return state.weatherResult.filter((entry) => entry.timestamp.getHours() === hour);
    },
  },
});
